
chrome.bookmarks.getTree(function(nodes) {
  console.log('******** bookmarks.getTree ', nodes)
})

chrome.bookmarks.search('Vue',function(items){ 

  console.log('********* bookmarks.search ', items)

  // for(var i = 0;i<items.length;i++) 
  // { 
  //  source[i] = items[i]; 

  // } 

 }); 

 // 删除具体文件
 chrome.bookmarks.remove(String(id));
 // 删除文件夹
 chrome.bookmarks.removeTree(String(id));
 // 创建
 chrome.bookmarks.create({
  'parentId': id,
  'title': title
});
chrome.bookmarks.update(id, {
  title: title
});



console.log('[background.js] ********* background thread ')

chrome.runtime.onMessage.addListener(function(request, sender, sendResponse){
  console.log('[background.js] ********* request ', request, sender, sendResponse)

  sendResponse('我已收到你的消息：'+JSON.stringify(request));


  getCurrentTabId(getTabId);

  return true;
})


function someMethod(){
  console.log('[background.js] someMethod call ')
}



/**
 * 获取当前选项卡id
 * @param callback - 获取到id后要执行的回调函数
 */
function getCurrentTabId(callback) {
  chrome.tabs.query({active: true, currentWindow: true}, function (tabs) {
      if (callback) {
          callback(tabs.length ? tabs[0].id: null);
      }
  });
}

function getTabId(tabId) {
  chrome.tabs.sendMessage(tabId, 'aaaa', function(response) {
    console.log('[background.js] ********* tabs.sendMessage ', response)
  });
}


